package com.zh.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Result<T> {

    private Integer code;
    private String msg;
    private T data;

    private Map<String,Object> map = new HashMap<>(); //动态数据
    //成功
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.code = 1;
        result.msg="success";
        result.data = data;
        return result;
    }

    //成功
    public static <T> Result<T> success( ) {
        Result<T> result = new Result<>();
        result.code = 1;
        result.msg="success";
        result.data=null;
        return result;
    }

    //失败
    public static <T> Result<T> error(String msg) {
        Result<T> result = new Result<>();
        result.code = 0;
        result.msg = msg;
        return result;
    }
    //失败
    public static <T> Result<T> error() {
        Result<T> result = new Result<>();
        result.code = 0;
        result.msg = "error";
        return result;
    }

    public Result<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }
}
